import requests
import json
import sys
import os

# 添加项目根目录到系统路径
current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.dirname(current_dir))

from ai.config import HEADERS, BASE_URL  # 从config模块导入统一配置

def stream_chat_completion(image_id):
    """流式聊天补全请求"""
    payload = {
        "stream": False,
        "incremental_output": True,
        "chat_type": "t2t",
        "model": "qwen2.5-vl-72b-instruct",
        "messages": [{
            "role": "user",
            "content": [
                {"type": "text", "text": "识别文本,仅返回图片中确定的内容", "chat_type": "t2t", "feature_config": {"thinking_enabled": False}},
                {"type": "image", "image": image_id}
            ]
        }],
        "session_id": "4c83217c-bce9-4c0d-bd74-7e5ec5b956a0",
        "chat_id": "ee3eebea-30be-41e9-8158-8323c8415fb8",
        "id": "896b9b25-0322-4c48-a87b-4c5a18b826ce"
    }
    print("正在发送请求...")
    print(f"请求URL: {BASE_URL + 'chat/completions'}")
    print(f"请求头: {HEADERS}")
    print(f"请求体: {json.dumps(payload, indent=2, ensure_ascii=False)}")

    try:
        response = requests.post(
            BASE_URL + 'chat/completions',
            headers=HEADERS,
            json=payload,
            stream=False
        )
        response.raise_for_status()
        return response.json()
    except Exception as e:
        print(f"请求失败: {str(e)}")
        print(f"响应状态码: {response.status_code}")
        print(f"响应内容: {response.text}")
        return None

if __name__ == '__main__':
    image_id = input("请输入图片ID: ").strip()
    result = stream_chat_completion(image_id)
    print("\n完整响应:")
    print(json.dumps(result, indent=2, ensure_ascii=False))